﻿using DataManage.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataManage.Data
{
    /// <summary>
    /// 数据帧点表
    /// </summary>
    [Serializable]
    public class DataFramePointTable
    {
        private int? cellCount;
        private VariableType assignmentIndex;


        /// <summary>
        /// 点表Key值
        /// </summary>
        public string TimeStamp = Guid.NewGuid().ToString();
        /// <summary>
        /// 名称
        /// </summary>
        public string Name {  get; set; }
        /// <summary>
        /// 表格显示顺序
        /// </summary>
        public int DisplaySequence {  get; set; }
        /// <summary>
        ///起始CANID
        /// </summary>
        public ulong CANID { get; set; }
        /// <summary>
        /// 终止CANID
        /// <para>随着PCLogin的配置修改</para>
        /// <para>如果是单帧，则CANID和EndCANID一致</para>
        /// <para>不改源地址，改PF部分</para>
        /// </summary>
        public ulong EndCANID { get; set; }
        /// <summary>
        /// 赋值枚举
        /// </summary>
        public VariableType AssignmentIndex { get => assignmentIndex; set { assignmentIndex = value; SetAreaFrame_CellCountEnable(); } }
        /// <summary>
        /// 资源Key值
        /// 针对不同的Key调用不同的资源
        /// <para>刷新太频繁，反射效率太低</para>
        /// </summary>
        public ResourceType ResourceIndex { get; set; }
        /// <summary>
        /// 单体数
        /// </summary>
        public int? CellCount { get => cellCount; set { cellCount = value; SetEndCANId(); } }
        /// <summary>
        /// 是否为固定帧
        /// <para>若为非固定帧则可以修改源地址</para>
        /// </summary>
        public bool IsFixedFrame { get; set; }
        /// <summary>
        /// 固定帧数
        /// <para>同一个帧ID分多帧发送数据</para>
        /// <para>接收到的帧数＝固定帧数</para>
        /// </summary>
        public int FrameNum { get; set; }
        /// <summary>
        /// 是否为范围帧
        /// <para>例如：单体电压、单体温度</para>
        /// </summary>
        //public bool IsAreaFrame {  get; set; }
        /// <summary>
        /// 数据段起始索引，单位：byte
        /// </summary>
        public int StartIndex { get; set; }
        /// <summary>
        /// 数据长度，单位：byte
        /// <para>若为故障数据帧，该长度为分割长度</para>
        /// </summary>
        public int DataLength { get; set; }
        /// <summary>
        /// 单字节中的Bit位置
        /// <para>故障帧</para>
        /// </summary>
        public int BitIndex { get; set; }
        /// <summary>
        /// 算法规则
        /// <para>int：字节索引</para>
        /// <para>int → 0：&，1：<<，2：>></para>
        /// <para>用于多字节数据时，指定字节需要进行算法矫正得到指定结果值</para>
        /// </summary>
        public List<Tuple<int, int, byte>> AlgorithmicRules { get; set; }
        /// <summary>
        /// 多字节顺序规则
        /// <para>true：高→低</para>
        /// <para>false：低→高</para>
        /// </summary>
        public bool SequentialRules_H {  get; set; }
        /// <summary>
        /// 帧类型
        /// </summary>
        public DataFrameType FrameType { get; set; }
        /// <summary>
        /// 比例因子
        /// </summary>
        public double ScaleFactor {  get; set; }
        /// <summary>
        /// 起始范围
        /// </summary>
        public double StartValue {  get; set; }
        /// <summary>
        /// 截止范围
        /// </summary>
        public double EndValue { get; set; }
        /// <summary>
        /// 偏移量
        /// </summary>
        public double Offset {  get; set; }
        /// <summary>
        /// 发送周期，单位：ms
        /// </summary>
        public int TransmissionCycle { get; set; }
        /// <summary>
        /// 所属的页面类型
        /// </summary>
        public PageType BelongPageType {  get; set; }
        /// <summary>
        /// 所属从板类型
        /// <para>用于非固定帧时，修改指定CANID的源地址</para>
        /// </summary>
        public SubTermType SubTerm { get; set; }

        /// <summary>
        /// 范围帧使能、单体数绑定AssignmentIndex字段
        /// </summary>
        private void SetAreaFrame_CellCountEnable()
        {

        }
        /// <summary>
        /// ENDCANID绑定单体数字段
        /// </summary>
        private void SetEndCANId()
        {

        }
    }
}
